package com.ccrfid.rmc6.resource.business.patrol;

import com.ccrfid.rmc6.appconfig.exception.pojo.AppException;
import com.ccrfid.rmc6.entity.business.patrol.PatrolLocationEntity;
import com.ccrfid.rmc6.entity.business.patrol.PatrolTimeRangeEntity;
import com.ccrfid.rmc6.entity.poi.PoiLocationEntity;
import com.ccrfid.rmc6.pojo.dto.patrol.PatrolGroupDto;
import com.ccrfid.rmc6.pojo.dto.patrol.PatrolPersonnelDto;
import com.ccrfid.rmc6.service.business.patrol.PatrolConfigService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;

@Path("patrol")
@Produces(MediaType.APPLICATION_JSON)
public class PatrolConfigResource {
    @Autowired
    private PatrolConfigService patrolConfigService;

    //获取巡控时段
    @GET
    @Path("time-ranges")
    public List<PatrolTimeRangeEntity> getPatrolTimeRanges() {
        return patrolConfigService.getPatrolTimeRanges();
    }

    //巡控组设置
    //************
    //获取巡控组列表
    @GET
    @Path("groups")
    public List<PatrolGroupDto> getPatrolGroupInfoList() {
        return patrolConfigService.getPatrolGroupInfoList();
    }

    //获取某个巡控组
    @GET
    @Path("group/{groupId}")
    public PatrolGroupDto getPatrolGroupInfo(@PathParam("groupId") Long groupId) {
        return patrolConfigService.getPatrolGroupInfo(groupId);
    }

    //获取可添加到巡控组的警员信息
    @GET
    @Path("group/personnels")
    public List<PatrolPersonnelDto> getPatrolPersonnelList() {
        return patrolConfigService.getPatrolPersonnelList();
    }

    //新增一个巡控组
    @POST
    @Path("group")
    @Consumes(MediaType.APPLICATION_JSON)
    public PatrolGroupDto createPatrolGroupInfo(PatrolGroupDto patrolGroup) throws AppException {
        return patrolConfigService.createPatrolGroupInfo(patrolGroup);
    }

    //修改巡控组
    @PUT
    @Path("group/{groupId}")
    @Consumes(MediaType.APPLICATION_JSON)
    public PatrolGroupDto updatePatrolGroupInfo(@PathParam("groupId") Long groupId, PatrolGroupDto patrolGroup)
            throws AppException {
        return patrolConfigService.updatePatrolGroupInfo(groupId, patrolGroup);
    }

    //删除一个巡控组
    @DELETE
    @Path("group/{groupId}")
    public Boolean deletePatrolGroupInfo(@PathParam("groupId") Long groupId) throws AppException {
        return patrolConfigService.deletePatrolGroupInfo(groupId);
    }

    //巡控区域设置
    //************
    //获取所有巡控区域
    @GET
    @Path("locations")
    public List<PatrolLocationEntity> getPatrolLocationList() {
        return patrolConfigService.getPatrolLocationList();
    }

    //获取可添加到巡控区域的区域信息
    @GET
    @Path("free-locations")
    public List<PoiLocationEntity> getFreeLocations() {
        return patrolConfigService.getFreeLocations();
    }

    //获取某个巡控区域
    @GET
    @Path("location/{locationId}")
    public PatrolLocationEntity getPatrolLocation(@PathParam("locationId") Long locationId) {
        return patrolConfigService.getPatrolLocation(locationId);
    }

    //添加某个巡控区域
    @POST
    @Path("location")
    @Consumes(MediaType.APPLICATION_JSON)
    public PatrolLocationEntity createPatrolLocation(PatrolLocationEntity patrolLocation) throws AppException {
        return patrolConfigService.createPatrolLocation(patrolLocation);
    }

    //修改某个巡控区域
    @PUT
    @Path("location/{locationId}")
    @Consumes(MediaType.APPLICATION_JSON)
    public PatrolLocationEntity updatePatrolLocation(@PathParam("locationId") Long locationId,
                                                     PatrolLocationEntity patrolLocation) throws AppException {
        return patrolConfigService.updatePatrolLocation(locationId, patrolLocation);
    }

    //删除某个巡控区域
    @DELETE
    @Path("location/{locationId}")
    public Boolean deletePatrolLocation(@PathParam("locationId") Long locationId) throws AppException {
        return patrolConfigService.deletePatrolLocation(locationId);
    }
}
